package com.anttribe.components.db.metadata.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author zhaoyong
 * @date 2020-12-30
 */
@Getter
@Setter
@ToString
public class DbSchema {

    /**
     * 全名(catalog.schema)
     */
    private String fullName;

    /**
     * 目录
     */
    private String catalog;

    /**
     * 模式
     */
    private String schema;

    /**
     * 数据库表
     */
    private List<DbTable> tables;

    public String getFullName() {
        if (StringUtils.isEmpty(fullName)) {
            StringBuilder fullNameStrB = new StringBuilder();
            if (!StringUtils.isEmpty(catalog)) {
                fullNameStrB.append(catalog);
            }
            if (!StringUtils.isEmpty(schema)) {
                if (!StringUtils.isEmpty(catalog)) {
                    fullNameStrB.append('.');
                }
                fullNameStrB.append(schema);
            }
            fullName = fullNameStrB.toString();
        }
        return fullName;
    }

}
